package com.stu.controller.student;

import com.stu.Dto.StuInformationDto;
import com.stu.pojo.ImageInfor;
import com.stu.result.Result;
import com.stu.serive.StuInformationService;
import com.stu.vo.StuInformationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/student")
public class StuInformationController {

    @Autowired
    private StuInformationService stuInformationService;

    /**
     * 查询学生个人信息
     * 学生只能查询个人的信息，系统自动操作，一定要提供正确的id
     * @param id
     * @return
     */
    @GetMapping("/information")
    private Result<StuInformationVo> StuInformationSelect(@RequestParam Long id){
        StuInformationVo stuInformationVo = stuInformationService.selectById(id);
        return Result.success(stuInformationVo);
    }

    /**
     * 新增学生信息
     * @param stuInformationDto
     * @return
     */
    @PostMapping("/information")
    private Result StuInformationAdd(@RequestBody StuInformationDto stuInformationDto) {
        log.info("新增学生信息：{}",stuInformationDto);
        stuInformationService.addWithFamilyWithOther(stuInformationDto);
        return Result.success();
    }

    /**
     * 修改学生信息
     * @param stuInformationDto
     * @return
     */
    @PutMapping("/information")
    private Result StuInformationAlter(@RequestBody StuInformationDto stuInformationDto){
        //根据指定的id去修改指定的学生数据
        log.info("修改学生信息:{}",stuInformationDto);
        stuInformationService.updateWithFamilyWithOther(stuInformationDto);
        return Result.success();
    }

    /**
     * 修改或添加学生照片
     */
    @PutMapping("/image")
    public Result InsertStuImage(@RequestBody ImageInfor image){
        stuInformationService.InsertStuImage(image);
        return Result.success();
    }
}
